export const getDateArray = (timestampmillisecond) => {
    var aArray = []
        // 获取时间
    var mydate = new Date()
    if (timestampmillisecond) {
        mydate = new Date(timestampmillisecond)
    }
    var gettime = mydate.getTime()
        // 年
    var year = '' + mydate.getFullYear()
    var date = ''
    var getHours = ''
    var getMinutes = ''
    var getSeconds = ''
    var Month = ''
        // 月
    if ((mydate.getMonth() + 1) >= 0 && (mydate.getMonth() + 1) <= 9) {
        Month = '0' + (mydate.getMonth() + 1)
    } else {
        Month = '' + (mydate.getMonth() + 1)
    }
    // 日
    if (mydate.getDate() >= 0 && mydate.getDate() <= 9) {
        date = '0' + mydate.getDate()
    } else {
        date = '' + mydate.getDate()
    }
    // 时
    if (mydate.getHours() >= 0 && mydate.getHours() <= 9) {
        getHours = '0' + mydate.getHours()
    } else {
        getHours = '' + mydate.getHours()
    }
    // 分
    if (mydate.getMinutes() >= 0 && mydate.getMinutes() <= 9) {
        getMinutes = '0' + mydate.getMinutes()
    } else {
        getMinutes = '' + mydate.getMinutes()
    }
    // 秒
    if (mydate.getSeconds() >= 0 && mydate.getSeconds() <= 9) {
        getSeconds = '0' + mydate.getSeconds()
    } else {
        getSeconds = '' + mydate.getSeconds()
    }
    aArray[0] = gettime
    aArray[1] = Month
    aArray[2] = date
    aArray[3] = getHours
    aArray[4] = getMinutes
    aArray[5] = getSeconds
    aArray[7] = year + '-' + Month + '-' + date
    aArray[8] = year + '-' + Month + '-' + date + ' ' + getHours + ':' + getMinutes
    aArray[9] = year + '-' + Month + '-' + date + ' ' + getHours + ':' + getMinutes + ':' + getSeconds
    aArray[10] = year + '.' + Month + '.' + date
    aArray[11] = getHours + ':' + getMinutes + ':' + getSeconds
    aArray[12] = Month + '.' + date + ' ' + getHours + ':' + getMinutes + ':' + getSeconds
    aArray[13] = year + '.' + Month + '.' + date + ' ' + getHours + ':' + getMinutes
    aArray[14] = year + '/' + Month + '/' + date
    aArray[15] = Month + '.' + date + ' ' + ' ' + getHours + ':' + getMinutes
    aArray[16] = year + '.' + Month + '.' + date
    aArray[17] = year + '.' + Month + '.' + date + ' ' + getHours + ':' + getMinutes + ':' + getSeconds
    aArray[18] = year + '-' + Month 
    aArray[19] = year 
    return aArray


}
export const getDynamicDate = (type) =>{
    //type:day 最近七天时间， month：最近六个月，year：最近5年
    var aArray = [];
    var end = new Date();
    var start = new Date();
    if(type=="day"){
        start = getDateArray(start.setTime(start.getTime() - 3600 * 1000 * 24 * 6))[7];
        end = getDateArray(end)[7]
    }
    if(type=="month"){//最近六个月
        start = getDateArray(start.setTime(start.getTime() - 3600 * 1000 * 24 * 30 * 5))[7];
        end = getDateArray(end)[7]
    }
    if(type=="year"){//最近5年
        start = getDateArray(start.setTime(start.getTime() - 3600 * 1000 * 24 * 30 * 12 * 4))[19];
        end = getDateArray(end)[19]
    }
    aArray[0] = start
    aArray[1] = end
    return aArray
}

function add0(m) { return m < 10 ? '0' + m : m }
export const dateFormat = (timestamp) => {
        //shijianchuo是整数，否则要parseInt转换
        var time = new Date(timestamp);
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);

    }
    /* 数字转中文大写 */
export const numToChinese = (str) => {
    str = str + '';
    var len = str.length - 1;
    var idxs = [
        '',
        '十',
        '百',
        '千',
        '万',
        '十',
        '百',
        '千',
        '亿',
        '十',
        '百',
        '千',
        '万',
        '十',
        '百',
        '千',
        '亿',
    ];
    var num = [
        '零',
        '壹',
        '贰',
        '叁',
        '肆',
        '伍',
        '陆',
        '柒',
        '捌',
        '玖',
    ];
    return str.replace(/([1-9]|0+)/g, function($, $1, idx, full) {
        var pos = 0;
        if ($1[0] != '0') {
            pos = len - idx;
            if (idx == 0 && $1[0] == 1 && idxs[len - idx] == '十') {
                return idxs[len - idx];
            }
            return num[$1[0]] + idxs[len - idx];
        } else {
            var left = len - idx;
            var right = len - idx + $1.length;
            if (Math.floor(right / 4) - Math.floor(left / 4) > 0) {
                pos = left - (left % 4);
            }
            if (pos) {
                return idxs[pos] + num[$1[0]];
            } else if (idx + $1.length >= len) {
                return '零';
            } else {
                return num[$1[0]];
            }
        }
    });
}
//判断两个对象是否相等
export const isEqual= (objA, objB) => {
        //相等
        if (objA === objB) return objA !== 0 || 1 / objA === 1 / objB;
        //空判断
        if (objA == null || objB == null) return objA === objB;
        //类型判断
        if (Object.prototype.toString.call(objA) !== Object.prototype.toString.call(objB)) return false;

        switch (Object.prototype.toString.call(objA)) {
            case '[object RegExp]':
            case '[object String]':
                //字符串转换比较
                return '' + objA === '' + objB;
            case '[object Number]':
                //数字转换比较,判断是否为NaN
                if (+objA !== +objA) {
                    return +objB !== +objB;
                }

                return +objA === 0 ? 1 / +objA === 1 / objB : +objA === +objB;
            case '[object Date]':
            case '[object Boolean]':
                return +objA === +objB;
            case '[object Array]':
                //判断数组
                for (let i = 0; i < objA.length; i++) {
                    if (!this.isEqual(objA[i], objB[i])) return false;
                }
                return true;
            case '[object Object]':
                //判断对象
                let keys = Object.keys(objA);
                for (let i = 0; i < keys.length; i++) {
                    if (!this.isEqual(objA[keys[i]], objB[keys[i]])) return false;
                }

                keys = Object.keys(objB);
                for (let i = 0; i < keys.length; i++) {
                    if (!this.isEqual(objA[keys[i]], objB[keys[i]])) return false;
                }

                return true;
            default:
                return false;
        }
}

export const verifyDataType = (data,type) => {
    if (!Object.prototype.toString.call(data) == `[Object ${type}]`)return false;
    return true;
}